import sys
from PyQt5.QtWidgets import (QApplication, QMainWindow, QSplitter, QWidget, QVBoxLayout, 
                            QHBoxLayout, QLabel, QLineEdit, QTreeWidget, QTreeWidgetItem, 
                            QTabWidget, QPushButton, QTextEdit, QFrame, QListWidget, 
                            QListWidgetItem, QGroupBox, QFormLayout, QMenu, QAction)
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QFont, QIcon, QPixmap, QColor

class QyhtThinkUI(QMainWindow):
    def __init__(self):
        super().__init__()
        self.initUI()
        
    def initUI(self):
        # 设置窗口基本属性
        self.setWindowTitle('Pyqt5  UI')
        self.setGeometry(100, 100, 1200, 800)
        
        # 创建主布局
        main_widget = QWidget()
        self.setCentralWidget(main_widget)
        main_layout = QHBoxLayout(main_widget)
        
        # 创建分割器，用于左右布局
        splitter = QSplitter(Qt.Horizontal)
        
        # 添加左侧导航区
        self.left_nav = self.create_left_nav()
        splitter.addWidget(self.left_nav)
        
        # 添加右侧主操作区
        self.main_content = self.create_main_content()
        splitter.addWidget(self.main_content)
        
        # 设置分割器初始大小
        splitter.setSizes([250, 950])
        
        main_layout.addWidget(splitter)
        
    def create_left_nav(self):
        """创建左侧导航区域"""
        widget = QWidget()
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(10, 10, 10, 10)
        layout.setSpacing(15)
        
        # 顶部标识
        title_label = QLabel('Pyqt5 UI')
        title_font = QFont()
        title_font.setPointSize(12)
        title_font.setBold(True)
        title_label.setFont(title_font)
        title_label.setAlignment(Qt.AlignCenter)
        title_label.setStyleSheet("color: #2c3e50; margin: 10px 0px;")
        layout.addWidget(title_label)
        
        # 搜索栏
        search_layout = QHBoxLayout()
        search_label = QLabel("搜索:")
        self.search_input = QLineEdit()
        self.search_input.setPlaceholderText("Search...")
        self.search_input.setStyleSheet("padding: 5px; border-radius: 3px; border: 1px solid #ddd;")
        search_layout.addWidget(search_label)
        search_layout.addWidget(self.search_input)
        layout.addLayout(search_layout)
        
        # 分类导航
        nav_group = QGroupBox("导航分类")
        nav_layout = QVBoxLayout()
        
        self.nav_tree = QTreeWidget()
        self.nav_tree.setHeaderHidden(True)
        
        # 添加导航项
        item1 = QTreeWidgetItem(["导航分类1"])
        item1.addChild(QTreeWidgetItem(["子项1-1"]))
        item1.addChild(QTreeWidgetItem(["子项1-2"]))
        item1.addChild(QTreeWidgetItem(["子项1-3"]))
        
        item2 = QTreeWidgetItem(["导航分类2"])
        item2.addChild(QTreeWidgetItem(["子项2-1"]))
        item2.addChild(QTreeWidgetItem(["子项2-2"]))
        
        item3 = QTreeWidgetItem(["导航分类3"])
        
        self.nav_tree.addTopLevelItem(item1)
        self.nav_tree.addTopLevelItem(item2)
        self.nav_tree.addTopLevelItem(item3)
        
        # 默认展开第一个分类
        item1.setExpanded(True)
        
        nav_layout.addWidget(self.nav_tree)
        nav_group.setLayout(nav_layout)
        layout.addWidget(nav_group)
        
        # 快捷功能区
        shortcut_group = QGroupBox("快捷功能区")
        shortcut_layout = QVBoxLayout()
        
        # 搜索监控
        monitor_btn = QPushButton("搜索监控")
        monitor_btn.setStyleSheet("text-align: left; padding: 8px;")
        shortcut_layout.addWidget(monitor_btn)
        
        # RB Demos
        rb_btn = QPushButton("RB Demos")
        rb_btn.setStyleSheet("text-align: left; padding: 8px;")
        shortcut_layout.addWidget(rb_btn)
        
        # 其他快捷功能
        other_btn1 = QPushButton("系统设置")
        other_btn1.setStyleSheet("text-align: left; padding: 8px;")
        shortcut_layout.addWidget(other_btn1)
        
        other_btn2 = QPushButton("帮助中心")
        other_btn2.setStyleSheet("text-align: left; padding: 8px;")
        shortcut_layout.addWidget(other_btn2)
        
        shortcut_layout.addStretch()
        shortcut_group.setLayout(shortcut_layout)
        layout.addWidget(shortcut_group)
        
        layout.addStretch()
        
        return widget
    
    def create_main_content(self):
        """创建右侧主操作区域"""
        widget = QWidget()
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(10, 10, 10, 10)
        layout.setSpacing(10)
        
        # 顶部操作栏
        top_bar = QWidget()
        top_layout = QHBoxLayout(top_bar)
        
        # 项目和环境按钮
        project_btn = QPushButton("Projects")
        environ_btn = QPushButton("Environ")
        top_layout.addWidget(project_btn)
        top_layout.addWidget(environ_btn)
        
        top_layout.addStretch()
        
        # 用户信息
        user_widget = QWidget()
        user_layout = QHBoxLayout(user_widget)
        user_layout.setContentsMargins(0, 0, 0, 0)
        
        user_label = QLabel("Dychech")
        user_icon = QLabel()
        # 使用简单的圆形表示用户头像
        user_icon.setFixedSize(24, 24)
        user_icon.setStyleSheet("background-color: #3498db; border-radius: 12px;")
        
        user_layout.addWidget(user_label)
        user_layout.addWidget(user_icon)
        top_layout.addWidget(user_widget)
        
        layout.addWidget(top_bar)
        
        # 中间标签和内容区
        self.tab_widget = QTabWidget()
        
        # 列表1标签页
        list1_tab = self.create_list_tab("列表1内容")
        self.tab_widget.addTab(list1_tab, "列表1")
        
        # 列表2标签页
        list2_tab = self.create_list_tab("列表2内容")
        self.tab_widget.addTab(list2_tab, "列表2")
        
        # 列表3标签页
        list3_tab = self.create_list_tab("列表3内容")
        self.tab_widget.addTab(list3_tab, "列表3")
        
        layout.addWidget(self.tab_widget)
        
        # 底部代码区
        code_group = QGroupBox("包装调用：2133860")
        code_layout = QVBoxLayout()
        
        self.code_editor = QTextEdit()
        self.code_editor.setReadOnly(True)
        self.code_editor.setStyleSheet("background-color: #2c3e50; color: #ecf0f1; font-family: Consolas, monospace;")
        
        # 添加示例JSON代码
        sample_json = """{
    "name": "Qyht架构",
    "version": "1.0.0",
    "components": [
        "导航模块",
        "数据展示",
        "代码编辑"
    ],
    "status": "running",
    "last_updated": "2023-07-15T10:30:00Z"
}"""
        self.code_editor.setText(sample_json)
        
        code_layout.addWidget(self.code_editor)
        code_group.setLayout(code_layout)
        
        # 设置代码区高度
        code_group.setMaximumHeight(200)
        layout.addWidget(code_group)
        
        return widget
    
    def create_list_tab(self, tab_name):
        """创建列表标签页内容"""
        widget = QWidget()
        layout = QVBoxLayout(widget)
        
        # 示例卡片列表
        list_widget = QListWidget()
        list_widget.setViewMode(QListWidget.IconMode)
        list_widget.setIconSize(QSize(64, 64))
        list_widget.setResizeMode(QListWidget.Adjust)
        list_widget.setSpacing(15)
        
        # 添加示例项
        for i in range(6):
            item = QListWidgetItem()
            item.setText(f"{tab_name} - 项目 {i+1}")
            # 使用简单的方块表示图标，修复了颜色值的错误
            r = 52 + i * 30  # 红色分量 (0-255)
            g = 152 + i * 10  # 绿色分量
            b = 219 - i * 20  # 蓝色分量，使用数值代替了之前的db字符串
            
            # 确保颜色值在0-255范围内
            r = min(255, max(0, r))
            g = min(255, max(0, g))
            b = min(255, max(0, b))
            
            frame = QFrame()
            frame.setFixedSize(64, 64)
            frame.setStyleSheet(f"background-color: #{r:02x}{g:02x}{b:02x}; border-radius: 8px;")
            list_widget.setItemWidget(item, frame)
        
        layout.addWidget(list_widget)
        return widget

if __name__ == '__main__':
    app = QApplication(sys.argv)
    # 设置全局样式
    app.setStyle('Fusion')
    window = QyhtThinkUI()
    window.show()
    sys.exit(app.exec_())
    